﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WF.Common;
using System.Web.Security;
using WF.BusinessObject;

namespace WF.Web
{
    public partial class Header : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userName;
            string roleName;
            string deptName;
            string corpName;
            string positionName;

            SessionManager sm = new SessionManager();
            UserProfile user = sm.CurrentUser;
            Username.InnerText = string.Format("用户:{0}({1})", user.LoginName, user.Empname);

            if (user.LoginName == null || user.LoginName == "")
            {
                this.ClientScript.RegisterClientScriptBlock(GetType(), "jg", "<script type='text/javascript'>window.top.location.href='ErrorPage.aspx'</script>");
            }
            //UserProfile currentUser = sm.CurrentUser;

            //if (null == currentUser)
            //{
            //    userName = String.Empty;
            //    roleName = String.Empty;
            //    deptName = String.Empty;
            //    corpName = String.Empty;
            //    positionName = String.Empty;
            //}
            //else
            //{
            //    userName = currentUser.Empname;
            //    roleName = currentUser.RoleName;
            //    deptName = currentUser.DeptName;
            //    SystemSetting SystemSetting = new BusinessObject.SystemSetting();
            //    corpName = SystemSetting.GetValueByParamName("company ");
            //    positionName = currentUser.PositionName;
            //}

            //this.Username.InnerText = "用户：" + userName;
            //this.Role.InnerText = "角色：" + roleName;
            //this.Department.InnerText = "部门:" + deptName;
            //this.CorpName.InnerText = "公司:" + corpName;

            //if (string.IsNullOrEmpty(positionName))
            //{
            //    this.PositionName.Visible = false;
            //}
            //else
            //{
            //    this.PositionName.InnerText = "职位:" + positionName;
            //}
        }

        protected void btnLogout_Click(object sender, ImageClickEventArgs e)
        {
            FormsAuthentication.SignOut();
            if (null != this.Session)
            {
                this.Session.Clear();
            }
            string s = "window.parent.location='Login.aspx';";
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", s, true);
        }
    }
}